package com.xwd.constants;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;

public class BeanListCopyUtils extends BeanUtils {

    public static<S,T> List<T> copyListBeanProperties(List<S> sources, Supplier<T> target){
        return copyListProperties(sources,target,null);
    }

    public static<S,T> List<T>  copyListProperties(List<S> sources,Supplier<T> target,BeanListUtilsCallBack<S,T> callback){
        if (Objects.isNull(sources)) return null;
        List<T> result = new ArrayList<>(sources.size());
        for (S source : sources) {
            T t = target.get();
            copyProperties(source,t);
            if (Objects.nonNull(callback))
                callback.callBack(source,t);
            result.add(t);
        }
        return result;
    }
}
